using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Medianamik.SubsonicDALProvider.DAL
{
	/// <summary>
	/// Strongly-typed collection for the NodePropertyValue class.
	/// </summary>
	[Serializable]
	public partial class NodePropertyValueCollection : ActiveList<NodePropertyValue,NodePropertyValueCollection> 
	{	   
		public NodePropertyValueCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_NodePropertyValue table.
	/// </summary>
	[Serializable]
	public partial class NodePropertyValue : ActiveRecord<NodePropertyValue>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public NodePropertyValue()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public NodePropertyValue(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public NodePropertyValue(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public NodePropertyValue(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_NodePropertyValue", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarNodePropertyValueId = new TableSchema.TableColumn(schema);
				colvarNodePropertyValueId.ColumnName = "NodePropertyValueId";
				colvarNodePropertyValueId.DataType = DbType.Guid;
				colvarNodePropertyValueId.MaxLength = 0;
				colvarNodePropertyValueId.AutoIncrement = false;
				colvarNodePropertyValueId.IsNullable = false;
				colvarNodePropertyValueId.IsPrimaryKey = true;
				colvarNodePropertyValueId.IsForeignKey = false;
				colvarNodePropertyValueId.IsReadOnly = false;
				colvarNodePropertyValueId.DefaultSetting = @"";
				colvarNodePropertyValueId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarNodePropertyValueId);
				
				TableSchema.TableColumn colvarNodeId = new TableSchema.TableColumn(schema);
				colvarNodeId.ColumnName = "NodeId";
				colvarNodeId.DataType = DbType.Guid;
				colvarNodeId.MaxLength = 0;
				colvarNodeId.AutoIncrement = false;
				colvarNodeId.IsNullable = false;
				colvarNodeId.IsPrimaryKey = false;
				colvarNodeId.IsForeignKey = true;
				colvarNodeId.IsReadOnly = false;
				colvarNodeId.DefaultSetting = @"";
				
					colvarNodeId.ForeignKeyTableName = "medianamik_Node";
				schema.Columns.Add(colvarNodeId);
				
				TableSchema.TableColumn colvarPropertyId = new TableSchema.TableColumn(schema);
				colvarPropertyId.ColumnName = "PropertyId";
				colvarPropertyId.DataType = DbType.Guid;
				colvarPropertyId.MaxLength = 0;
				colvarPropertyId.AutoIncrement = false;
				colvarPropertyId.IsNullable = false;
				colvarPropertyId.IsPrimaryKey = false;
				colvarPropertyId.IsForeignKey = true;
				colvarPropertyId.IsReadOnly = false;
				colvarPropertyId.DefaultSetting = @"";
				
					colvarPropertyId.ForeignKeyTableName = "medianamik_Property";
				schema.Columns.Add(colvarPropertyId);
				
				TableSchema.TableColumn colvarLanguageId = new TableSchema.TableColumn(schema);
				colvarLanguageId.ColumnName = "LanguageId";
				colvarLanguageId.DataType = DbType.Guid;
				colvarLanguageId.MaxLength = 0;
				colvarLanguageId.AutoIncrement = false;
				colvarLanguageId.IsNullable = true;
				colvarLanguageId.IsPrimaryKey = false;
				colvarLanguageId.IsForeignKey = true;
				colvarLanguageId.IsReadOnly = false;
				colvarLanguageId.DefaultSetting = @"";
				
					colvarLanguageId.ForeignKeyTableName = "medianamik_Language";
				schema.Columns.Add(colvarLanguageId);
				
				TableSchema.TableColumn colvarValueX = new TableSchema.TableColumn(schema);
				colvarValueX.ColumnName = "Value";
				colvarValueX.DataType = DbType.String;
				colvarValueX.MaxLength = -1;
				colvarValueX.AutoIncrement = false;
				colvarValueX.IsNullable = true;
				colvarValueX.IsPrimaryKey = false;
				colvarValueX.IsForeignKey = false;
				colvarValueX.IsReadOnly = false;
				colvarValueX.DefaultSetting = @"";
				colvarValueX.ForeignKeyTableName = "";
				schema.Columns.Add(colvarValueX);
				
				TableSchema.TableColumn colvarIsApproved = new TableSchema.TableColumn(schema);
				colvarIsApproved.ColumnName = "IsApproved";
				colvarIsApproved.DataType = DbType.Boolean;
				colvarIsApproved.MaxLength = 0;
				colvarIsApproved.AutoIncrement = false;
				colvarIsApproved.IsNullable = false;
				colvarIsApproved.IsPrimaryKey = false;
				colvarIsApproved.IsForeignKey = false;
				colvarIsApproved.IsReadOnly = false;
				colvarIsApproved.DefaultSetting = @"";
				colvarIsApproved.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsApproved);
				
				TableSchema.TableColumn colvarIsDeleted = new TableSchema.TableColumn(schema);
				colvarIsDeleted.ColumnName = "IsDeleted";
				colvarIsDeleted.DataType = DbType.Boolean;
				colvarIsDeleted.MaxLength = 0;
				colvarIsDeleted.AutoIncrement = false;
				colvarIsDeleted.IsNullable = false;
				colvarIsDeleted.IsPrimaryKey = false;
				colvarIsDeleted.IsForeignKey = false;
				colvarIsDeleted.IsReadOnly = false;
				colvarIsDeleted.DefaultSetting = @"";
				colvarIsDeleted.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsDeleted);
				
				TableSchema.TableColumn colvarRevision = new TableSchema.TableColumn(schema);
				colvarRevision.ColumnName = "Revision";
				colvarRevision.DataType = DbType.Int32;
				colvarRevision.MaxLength = 0;
				colvarRevision.AutoIncrement = false;
				colvarRevision.IsNullable = false;
				colvarRevision.IsPrimaryKey = false;
				colvarRevision.IsForeignKey = false;
				colvarRevision.IsReadOnly = false;
				colvarRevision.DefaultSetting = @"";
				colvarRevision.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRevision);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_NodePropertyValue",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("NodePropertyValueId")]
		public Guid NodePropertyValueId 
		{
			get { return GetColumnValue<Guid>(Columns.NodePropertyValueId); }

			set { SetColumnValue(Columns.NodePropertyValueId, value); }

		}

		  
		[XmlAttribute("NodeId")]
		public Guid NodeId 
		{
			get { return GetColumnValue<Guid>(Columns.NodeId); }

			set { SetColumnValue(Columns.NodeId, value); }

		}

		  
		[XmlAttribute("PropertyId")]
		public Guid PropertyId 
		{
			get { return GetColumnValue<Guid>(Columns.PropertyId); }

			set { SetColumnValue(Columns.PropertyId, value); }

		}

		  
		[XmlAttribute("LanguageId")]
		public Guid? LanguageId 
		{
			get { return GetColumnValue<Guid?>(Columns.LanguageId); }

			set { SetColumnValue(Columns.LanguageId, value); }

		}

		  
		[XmlAttribute("ValueX")]
		public string ValueX 
		{
			get { return GetColumnValue<string>(Columns.ValueX); }

			set { SetColumnValue(Columns.ValueX, value); }

		}

		  
		[XmlAttribute("IsApproved")]
		public bool IsApproved 
		{
			get { return GetColumnValue<bool>(Columns.IsApproved); }

			set { SetColumnValue(Columns.IsApproved, value); }

		}

		  
		[XmlAttribute("IsDeleted")]
		public bool IsDeleted 
		{
			get { return GetColumnValue<bool>(Columns.IsDeleted); }

			set { SetColumnValue(Columns.IsDeleted, value); }

		}

		  
		[XmlAttribute("Revision")]
		public int Revision 
		{
			get { return GetColumnValue<int>(Columns.Revision); }

			set { SetColumnValue(Columns.Revision, value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Language ActiveRecord object related to this NodePropertyValue
		/// 
		/// </summary>
		public Medianamik.SubsonicDALProvider.DAL.Language Language
		{
			get { return Medianamik.SubsonicDALProvider.DAL.Language.FetchByID(this.LanguageId); }

			set { SetColumnValue("LanguageId", value.LanguageID); }

		}

		
		
		/// <summary>
		/// Returns a Node ActiveRecord object related to this NodePropertyValue
		/// 
		/// </summary>
		public Medianamik.SubsonicDALProvider.DAL.Node Node
		{
			get { return Medianamik.SubsonicDALProvider.DAL.Node.FetchByID(this.NodeId); }

			set { SetColumnValue("NodeId", value.NodeId); }

		}

		
		
		/// <summary>
		/// Returns a PropertyX ActiveRecord object related to this NodePropertyValue
		/// 
		/// </summary>
		public Medianamik.SubsonicDALProvider.DAL.PropertyX PropertyX
		{
			get { return Medianamik.SubsonicDALProvider.DAL.PropertyX.FetchByID(this.PropertyId); }

			set { SetColumnValue("PropertyId", value.PropertyId); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varNodePropertyValueId,Guid varNodeId,Guid varPropertyId,Guid? varLanguageId,string varValueX,bool varIsApproved,bool varIsDeleted,int varRevision)
		{
			NodePropertyValue item = new NodePropertyValue();
			
			item.NodePropertyValueId = varNodePropertyValueId;
			
			item.NodeId = varNodeId;
			
			item.PropertyId = varPropertyId;
			
			item.LanguageId = varLanguageId;
			
			item.ValueX = varValueX;
			
			item.IsApproved = varIsApproved;
			
			item.IsDeleted = varIsDeleted;
			
			item.Revision = varRevision;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varNodePropertyValueId,Guid varNodeId,Guid varPropertyId,Guid? varLanguageId,string varValueX,bool varIsApproved,bool varIsDeleted,int varRevision)
		{
			NodePropertyValue item = new NodePropertyValue();
			
				item.NodePropertyValueId = varNodePropertyValueId;
			
				item.NodeId = varNodeId;
			
				item.PropertyId = varPropertyId;
			
				item.LanguageId = varLanguageId;
			
				item.ValueX = varValueX;
			
				item.IsApproved = varIsApproved;
			
				item.IsDeleted = varIsDeleted;
			
				item.Revision = varRevision;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn NodePropertyValueIdColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn NodeIdColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn PropertyIdColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        public static TableSchema.TableColumn LanguageIdColumn
        {
            get { return Schema.Columns[3]; }

        }

        
        
        
        public static TableSchema.TableColumn ValueXColumn
        {
            get { return Schema.Columns[4]; }

        }

        
        
        
        public static TableSchema.TableColumn IsApprovedColumn
        {
            get { return Schema.Columns[5]; }

        }

        
        
        
        public static TableSchema.TableColumn IsDeletedColumn
        {
            get { return Schema.Columns[6]; }

        }

        
        
        
        public static TableSchema.TableColumn RevisionColumn
        {
            get { return Schema.Columns[7]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string NodePropertyValueId = @"NodePropertyValueId";
			 public static string NodeId = @"NodeId";
			 public static string PropertyId = @"PropertyId";
			 public static string LanguageId = @"LanguageId";
			 public static string ValueX = @"Value";
			 public static string IsApproved = @"IsApproved";
			 public static string IsDeleted = @"IsDeleted";
			 public static string Revision = @"Revision";
						
		}

		#endregion
		
		
		
	}

}

